package com.example.testservice;

import com.example.testservice.CountService.ICountService;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Intent i = new Intent("com.example.testservice.CountService");
		i.putExtra("start", 222);
//		
//		startService(i);
//		System.out.println("after service");
		bindService(i, sc, BIND_AUTO_CREATE);
		
	}
	
	private ServiceConnection sc = new ServiceConnection() {
		
		@Override
		public void onServiceDisconnected(ComponentName name) {
			countService = null;
		}
		
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			System.out.println("ComponentName =" + name.toString());
			countService = (ICountService)service;
			System.out.println("countService = " + countService.getCount());
		}
	};

	private ICountService countService;
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		stopService(new Intent(this, CountService.class));
	}
	
	
}
